package com.hzdl.car.mapper;

import com.hzdl.car.bean.Role;
import com.hzdl.car.sqlprovider.RoleSqlProvider;
import com.hzdl.car.vo.RoleVo;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface RoleMapper {
    @SelectProvider(type = RoleSqlProvider.class,method ="findRole" )
    List<Role> findRole(RoleVo roleVo);
    @Insert("insert into sys_role (roleName,roleDesc,available) values " +
            "(#{roleName},#{roleDesc},#{available})")
    int addRole(RoleVo roleVo);
    @Update("update sys_role set roleName=#{roleName},roleDesc=#{roleDesc},available=#{available} where roleId=#{roleId}")
    int update(RoleVo roleVo);
    @Delete("delete from sys_role where roleId=#{roleId} ")
    int delRole(RoleVo roleVo);
    @Delete("delete from sys_role_menu where rId=#{roleId} ")
    int delRoleMenu(RoleVo roleVo);
    @Delete("delete from sys_role_user where rId=#{roleId} ")
    int delRoleUser(RoleVo roleVo);
    @Select("select count(*) from sys_role_menu where rId=#{roleId}")
    int chkRoleMenu(RoleVo roleVo);
    @Select("select count(*) from sys_role_user where rId=#{roleId}")
    int chkRoleUser(RoleVo roleVo);
    @Delete("delete from sys_role_menu where rId=#{roleId}")
    int delMenuByRole(RoleVo roleVo);
    @Insert("insert into sys_role_menu (rId,mId) values (#{rId},#{mId})")
    int addRoleMenuByRole(@Param("rId") Integer rId,@Param("mId") Integer mId);
    @Select("select * from sys_role r inner join sys_role_user ru on r.roleId=ru.rId " +
            " inner join  sys_user u on ru.uId=u.userId " +
            " where u.userId=#{id}")
    List<Role> findRoleByUser(Integer id);
}
